package cn.wolfcode.wechat.service.impl;

import cn.wolfcode.wechat.domain.Menu;
import cn.wolfcode.wechat.mapper.MenuMapper;
import cn.wolfcode.wechat.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuServiceImpl implements IMenuService{

    @Autowired
    private MenuMapper menuMapper;

    @Override
    public int insert(Menu menu){
        return menuMapper.insert(menu);
    }

    @Override
    public int update(Menu menu){
        return menuMapper.update(menu);
    }

    @Override
    public List<Menu> getRootMenu() {
        return menuMapper.getRootMenu();
    }

    @Override
    public List<Menu> getSubMenu(Long id) {
        return menuMapper.getSubMenu(id);
    }


    @Override
    public void saveOrUpdate(Menu menu) {
        if (menu.getId() == null){
            menuMapper.insert(menu);
        }else {
            menuMapper.update(menu);
        }
    }
}
